<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="${pageContext.request.contextPath }/js/kindeditor-4.1.10/themes/default/default.css" type="text/css" rel="stylesheet">
<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath }/js/kindeditor-4.1.10/kindeditor-all-min.js"></script>
<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath }/js/kindeditor-4.1.10/lang/zh_CN.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-1.8.3.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/ajaxfileupload.js"></script>
<link id="easyuiTheme" rel="stylesheet" type="text/css"	href="${pageContext.request.contextPath }/js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/js/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/default.css">
<script type="text/javascript" src="${pageContext.request.contextPath }/js/easyui/jquery.easyui.min.js"></script>
<script	src="${pageContext.request.contextPath }/js/easyui/locale/easyui-lang-zh_CN.js"	type="text/javascript"></script>
<script src="${pageContext.request.contextPath }/js/outOfBounds.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath }/js/common.js" type="text/javascript"></script>
</head>

<body>
<div class="easyui-layout" data-options="fit:true">
	
	<div data-options="region:'center'" style="padding:5px">
	<table class="easyui-datagrid" id="memberList"
       data-options="singleSelect:false,collapsible:true,pagination:true,url:'${pageContext.request.contextPath }/admin/activemanager/active/list.do',method:'get',pageSize:30,toolbar:toolbar,fitColumns:true">
    <input id="ss" class="easyui-searchbox" style="width: 300px" data-options="searcher:doSearchActive,prompt:'请输入要查找的id',menu:'#mm'"></input>
    <thead>
        <tr>
        	<th data-options="field:'ck',checkbox:true"></th>
        	<th data-options="field:'id',width:70,align:'center'">活动id</th>
            <th data-options="field:'title',width:70,align:'center'">活动名</th>
            <th data-options="field:'keywords',width:200,align:'center',formatter:HONGXIN.activeType">活动种类</th>
            <!-- <th data-options="field:'keywords',width:200,align:'center',formatter:HONGXIN.activeType">活动种类</th> -->
            <th data-options="field:'summary',width:150,align:'center'">概要</th>
            <th data-options="field:'source',width:100,align:'center'">来源</th>
            <th data-options="field:'editor',width:100,align:'center'">作者</th>
            <th data-options="field:'imgUrl',width:40,align:'center'">图片</th>
             <th data-options="field:'content',width:100,align:'center',hidden:true">活动详情</th>
            <th data-options="field:'levelclass',width:40,align:'center',formatter:HONGXIN.activeClass">活动等级</th>
            <th data-options="field:'publishTime',width:130,align:'center'">发布时间</th>
        </tr>
    </thead>
	</table>
	</div>
</div>
</body>
<div id="memberAddWindow" class="easyui-window" title="新增会员" data-options="modal:true,closed:true,iconCls:'icon-save',href:'${pageContext.request.contextPath }/admin/activemanager/article_add.do'" style="width:1000px;height:500px;padding:10px;" />
<div id="memberEditWindow" class="easyui-window" title="编辑会员" data-options="modal:true,closed:true,iconCls:'icon-save',href:'${pageContext.request.contextPath }/admin/activemanager/active_edit.do'" style="width:1000px;height:500px;padding:10px;" />

	
<script>

function doSearchActive(value, name) {
	var options = $('#memberList').datagrid('getPager').data('pagination').options;
	
	if (value == ''){
		//参数options.pageNumber, options.pageSize
		//发送post强求
		var params = {"page":options.pageNumber,"rows":options.pageSize};
		$.post("${pageContext.request.contextPath }/admin/activemanager/active/list.do",params, function(oData) {
			console.info(oData);
			$('#memberList').datagrid('loadData', {
				"total" : oData.total,
				"rows" : oData.rows
			});
		},"json");
	}else{
		//参数options.pageNumber, options.pageSize
		//发送post强求
		var params = {"page":options.pageNumber,"rows":options.pageSize, id:value/* "name":name,"value":value */};
		$.post("${pageContext.request.contextPath }/admin/activemanager/active/list.do",params, function(oData) {
			if(oData.total == 0){
				$.messager.alert('提示','没有查询到相关内容!');
			}else{
			$('#memberList').datagrid('loadData', {
				"total" : oData.total,
				"rows" : oData.rows
			});
				
			}
		},"json");

	}
};

    function getSelectionsIds(){
    	var memberList = $("#memberList");
    	var sels = memberList.datagrid("getSelections");
    	var ids = [];
    	for(var i in sels){
    		ids.push(sels[i].id);
    	}
    	ids = ids.join(",");
    	return ids;
    }
    
    var toolbar = [{
        text:'新增',
        iconCls:'icon-add',
        handler:function(){
        	var ids = getSelectionsIds();
        	if(ids.length == 0) {
        		$.messager.alert('提示', '请选择您要添加活动的介绍');
        		return;
        	}
        	if(ids.indexOf(',') > 0) {
        		$.message.alert('提示', '只能选择一则活动');
        		return ;
        	}
        	/* alert("${pageContext.request.contextPath }/admin/activemanager/article_add.do?pid="+ids) */
        	window.parent.click_me("admin/activemanager/article_add.do?pid="+ids, "活动添加详情");
        	/* $("#memberAddWindow").window().window("open"); */
        } 
    },{
        text:'编辑',
        iconCls:'icon-edit',
        handler:function(){
        	var ids = getSelectionsIds();
        	if(ids.length == 0){
        		$.messager.alert('提示','必须选择一则用户才能编辑!');
        		return ;
        	}
        	if(ids.indexOf(',') > 0){
        		$.messager.alert('提示','只能选择一则活动!');
        		return ;
        	}
        	
        	$("#memberEditWindow").window({
        		onLoad :function(){
        			//回显基础数据
        			//获取选中行的数据
        			var data = $("#memberList").datagrid("getSelections")[0];
        			
        			console.info(data)
        			$("#articleEditForm").form("load",data);
        			HONGXIN.init({
        				//回显图片
        				"pics" : data.imgUrl,
        				//回显文章分类
        				"cid" : data.name,
        				//"name" : date.name,
			
        			});
        			var articleEditEditor ;
        			$(function(){
        				//实例化编辑器
        				articleEditEditor = HONGXIN.createEditor("#articleEditForm [name=content]");
        			});
        			
        			// 加载文章描述
        			$.getJSON('articleDetail?id='+data.id,function(_data){
        				
        				if(_data.status == 200){
        					
        					articleEditEditor.html(_data.data);
        				}
        			});
        			
        		}
        		
        		}
        	).window("open");

        }
    },{
        text:'删除',
        iconCls:'icon-cancel',
        handler:function(){
        	var ids = getSelectionsIds();
        	if(ids.length == 0){
        		$.messager.alert('提示','未选中活动!');
        		return ;
        	}
        	$.messager.confirm('确认','确定删除ID为 '+ids+' 的活动吗？',function(r){
        	    if (r){
        	    	var params = {"ids":ids};
                	$.post("${pageContext.request.contextPath }/admin/activemanager/active/delete.do",params, function(data){
            			if(data.status == 200){
            				 //刷新当前页面.
           				 $.messager.alert('提示', data.data, 'info', function() {
           						$("#memberList").datagrid("reload");
           				});
            			}else{
            				 //刷新当前页面.
           				 $.messager.alert('提示', data.data, 'info', function() {
           						$("#memberList").datagrid("reload");
           				});
            			}
            		},'json');
        	    }
        	});
        }
    }];

</script>